package service

import (
	"context"
	"gitee.com/xiao_hange/go-admin-log/log/domain"
	"gitee.com/xiao_hange/go-admin-log/log/repository"
	"gitee.com/xiao_hange/go-admin-pkg/pkg/logger"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/trace"
)

type LogService interface {
	InsertDocument(ctx context.Context, index, message string) error
	SearchLog(ctx context.Context, index string, page, limit int) ([]domain.Log, int, error)
}
type logService struct {
	repo   repository.LogRepository
	l      logger.AppLogger
	tracer trace.Tracer
}

func NewLogService(repo repository.LogRepository, l logger.AppLogger) LogService {
	return &logService{
		repo:   repo,
		l:      l,
		tracer: otel.Tracer("Log服务-Server层"),
	}
}

func (l *logService) InsertDocument(ctx context.Context, index, message string) error {
	return l.repo.InputLog(ctx, domain.Log{
		Index:   index,
		Message: message,
	})
}

func (l *logService) SearchLog(ctx context.Context, index string, page, limit int) ([]domain.Log, int, error) {
	lsits, total, err := l.repo.SearchLog(ctx, index, page, limit)
	return lsits, total, err
}
